// pages/index3/index3.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    year: new Date().getFullYear(), // 年份
    month: new Date().getMonth() + 1, // 月份
    day: new Date().getDate(),
    // str: MONTHS[new Date().getMonth()],  // 月份字符串
    demo4_days_style: [],
    qdSJ: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

    wx.setNavigationBarTitle({
      title: '签到日历',
    })
    wx.setNavigationBarColor({
      frontColor: '#ffffff',
      backgroundColor: '#ff6700',
    })
    wx.getStorage({
      key: 'tempList',
      success: (res) => {
        console.log(res)
        this.setData({
          qdSJ: res.data
        })
      },
    })

    const days_count = new Date(this.data.year, this.data.month, 0).getDate();
    // console.log("days_count = " + this.data.year)
    let now = new Date();
    var d = now.getDate();
    var t = this.data.qdSJ;

    let demo4_days_style = new Array;
    for (let i = 1; i <= days_count; i++) {
      if (d == i) {
      
        demo4_days_style.push({
          month: 'current',
          day: i,
          color: 'white',
          background: '#0094ff'
        });
      }

      for (let j = 0; j < t.length; j++) {
        if (i == t[j]) {
          console.log("123214132")
          demo4_days_style.push({
            month: 'current',
            day: i,
            color: 'white',
            background: '#ff6700'
          });
        }

      }
    }

    this.setData({
      demo4_days_style
    })

  },
  // 点击获取某一天
  dayClick: function(event) {
    console.log(event.detail);


    if (event.detail.color != "#c3c6d1") {
      wx.navigateTo({
        url: '../Userlist/Userlist?day=' + event.detail.day,
      })
    }

    let demo4_days_style = new Array;
    // 点击那里那里蓝
    if (event.detail.color != "#c3c6d1") {
      demo4_days_style.push({
        month: 'current',
        day: event.detail.day,
        color: 'white',
        background: '#0094ff'
      });
      this.setData({
        demo4_days_style
      });
      console.log(demo4_days_style)
    }


  },

  // 回到今天
  backToNowday: function() {
    let year = new Date().getFullYear();
    let month = new Date().getMonth() + 1;
    let day = new Date().getDate();
    this.setData({
      year: year,
      month: month,
      day: day
    });
    // 单独设置今天的背景颜色
    const days_count = new Date(this.data.year, this.data.month, 0).getDate();
    // console.log("days_count = " + this.data.year)
    let demo4_days_style = new Array;
    for (let i = 1; i <= days_count; i++) {
      if (day == i) {
        demo4_days_style.push({
          month: 'current',
          day: i,
          color: 'white',
          background: '#0094ff'
        });
      }
    }
    this.setData({
      demo4_days_style
    });

  },
  btnText: function() {
    let D = new Date();
    console.log(D.getHours());
    console.log(D.getMinutes());
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    // wx.setStorage({
    //   key: 'tmep',
    //   data: this.data.qdSJ,
    // })


    let tempList = this.data.qdSJ;
    wx.getStorage({
      key: 'timeList',
      success: (res) => {

        if (res.data[2] != tempList[tempList.length - 1]) {
          tempList.push(res.data[2])
        }




        this.setData({
          qdSJ: tempList
        })


        wx.setStorage({
          key: 'tempList',
          data: this.data.qdSJ,
        })
      },
    })




  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})